/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.lidovky.articles.articlesData.pesta;

import java.util.List;

/**
 *
 * @author x211800
 */
public class ColumnOfNote extends Columns {

    private static ColumnOfNote instance;
    private StringBuffer note;

    private ColumnOfNote() {
    }

    public static ColumnOfNote instanceOf(String[] columns, String additionalNotes) {
        if (instance == null) {
            instance = new ColumnOfNote();
        }
        instance.parseColumn(columns, additionalNotes);

        return instance;
    }

    private void parseColumn(String[] columns, String additionalNotes) {
        note = new StringBuffer("");

        if (removeTextDelimits(columns[4]) != null) {
            note.append(removeTextDelimits(columns[4]));
        }

        if (columns.length > 8 && columns[8] != null && !columns[8].equals(EMPTY_STRING)) {
            addSemicolon();
            note.append(removeTextDelimits(columns[8]));
        }

        if (columns.length > 9 && columns[9] != null && !columns[9].equals(EMPTY_STRING) && !columns[9].equals(columns[8])) {
            addSemicolon();
            note.append(removeTextDelimits(columns[9]));
        }

        if (additionalNotes.length() != 0) {
            String cleanedAdditionalNotes = additionalNotes.trim();
            addSemicolon();
            note.append(cleanedAdditionalNotes);
        }
    }

    private void addSemicolon() {
        if (note.length() > 1) {
            note.append(SEMICOLON).append(WHITESPACE);
        }
    }

    public String getNote() {
        return note.toString();
    }
}
